package personal.jinhui.paprika.providers;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;

public class AccountsHelper {
	private Context mContext;

	public AccountsHelper(Context context) {
		mContext = context;
	}

	public void addAccount(String jid, String password, String fulljid, String avatarid) {
		ContentValues values = new ContentValues();
		values.put(UserDataMeta.AccountsTable.JID, jid);
		values.put(UserDataMeta.AccountsTable.PASSWORD, password);
		values.put(UserDataMeta.AccountsTable.FULLJID, fulljid);
		values.put(UserDataMeta.AccountsTable.AVATARID, avatarid);
		mContext.getContentResolver().insert(
				UserDataMeta.AccountsTable.CONTENT_URI, values);
	}

	public String getAccounts() {
		Cursor c = mContext.getContentResolver().query(
				UserDataMeta.AccountsTable.CONTENT_URI, null, null, null, null);
		StringBuilder strSb = new StringBuilder();
		while (c.moveToNext()) {
			strSb.append(c.getString(c
					.getColumnIndex(UserDataMeta.AccountsTable.JID)));
			strSb.append(",");
		}
		return strSb.toString();
	}
}
